;;;Custom DTEXT. Auto sets layer attribs and text size. LINE-under-last option.
;;;
;;;	AUTHOR: HENRY C. FRANCIS
;;;		425 N. ASHE ST.
;;;		SOUTHERN PINES, NC 28387
;;;              
;;;		All rights reserved without prejudice.
;;;
;;;	Copyright:	2-23-96
;;;	Edited:		6-13-2005
;;;
;;;Added explicit load for upoint, ukword, uangle (no longer dependent upon external load).
;;;
(defun c:dtxt ( / pt1 tp1 dtjst)
  (IF c:mklayr NIL (LOAD "mklayr" "\nFile MKLAYR.LSP not loaded! "))
  (c:svlayr)
  (IF upoint NIL (LOAD "upoint" "\nFile UPOINT.LSP not loaded! "))
  (IF ukword NIL (LOAD "ukword" "\nFile UKWORD.LSP not loaded! "))
  (IF uangle NIL (LOAD "uangle" "\nFile UANGLE.LSP not loaded! "))
      (if txtsize
        (txtsize nil)
        (progn(load "txtsize" "\nFile TXTSIZE.LSP not found! ")(txtsize nil))
      )
      (while
        (and
          (not tp1)
          (eq(setq pt1 (upoint 1 "J" "Justify/<Start point>" nil nil))"J")
        );and
        (setq dtjst (ukword 1 "A F C M R TL TC TR ML MC MR BL BC BR" "Align/Fit/Center/Middle/Right/TL/TC/TR/ML/MC/MR/BL/BC/BR: "(if dtjst dtjst "")))
        (if(or(eq dtjst "F")(eq dtjst "A"))
          (setq tp1 (upoint 1 "" "First text line point" nil nil)
                tp2 (upoint 1 "" "Second text line point" nil tp1))
        );if
      );while
      (if dtjst
        nil
        (setq dtjst "L")
      );if
  (setq llt "-"
;        prod "DRWG"
        modf "NOTE"
        colr txcolr
;        dimsc (getvar "DIMSCALE")
  );setq
  (if dimscl nil (load"dimscl"))
  (dimscl)
  (if gvpno nil (load"gvpno"))
  (gvpno)
;;;  (if(not(eq dtjst "A"))
;;;    (if txtsize
;;;      (txtsize nil)
;;;      (progn(load "txtsize" "\nFile TXTSIZE.LSP not found! ")(txtsize nil))
;;;    )
;;;  );if
  (if(not(or(eq dtjst "F")(eq dtjst "A")))
    (setq rang (uangle 1 "" "Rotation angle" 0 pt1)
          angl (* 180(/ rang pi))
    );setq
  );if
  (c:mklayr)
  (setvar "TEXTSIZE" txtht)
  (princ "\nText: ")
(if(eq dtjst "L")
  (command ".dtext" pt1 txtht angl)
  (cond
    ((eq dtjst "F")
      (command ".dtext" "j" dtjst tp1 tp2 txtht))
    ((eq dtjst "A")
      (command ".dtext" "j" dtjst tp1 tp2))
    (dtjst
      (command ".dtext" "j" dtjst pt1 txtht angl))
  );cond
);if
(setq ulin (ukword 1 "Yes No" "Underline the last line?" "No"))
(if(eq ulin "Yes")
(progn
  (setq tent (entget(entlast))
        tp1 (cdr(assoc 10 tent))
        tbox (textbox tent)
        txht (cdr(assoc 40 tent))
        tdis (distance (nth 0 tbox)(nth 1 tbox))
        tang (cdr(assoc 50 tent))
        tbang
          (if (> tdis 0)
            (+ tang(atan txht (sqrt(-(* tdis tdis)(* txht txht)))))
            0
          );if
        tp2 (polar tp1 tbang tdis)
        bxp1 (polar tp1 (- tang(* pi 0.75))(* 1.414214(/ txht 1.8)))
        bxp2 (polar bxp1 (+ tang(* pi 0.50))(+(* 2.00(/ txht 1.8))txht))
        bxp4 (polar tp2 (+ tang(* pi 0.25))(* 1.414214(/ txht 1.8)))
        bxp3 (polar bxp4 (- tang(* pi 0.50))(+(* 2.00(/ txht 1.8))txht))
        bxp1 (trans(list(car bxp1)(cadr bxp1))0 1)
        bxp2 (trans(list(car bxp2)(cadr bxp2))0 1)
        bxp3 (trans(list(car bxp3)(cadr bxp3))0 1)
        bxp4 (trans(list(car bxp4)(cadr bxp4))0 1)
  );setq
  (if (> tdis 0)
    (command ".line" bxp1 bxp3 "")
  );if
;  (command ".line" lp1 lp2 "")
);progn
);if
(princ)
);defun
